package nl.hro.mgdd.team4.raidersofhexagoniland.Scenes;

import java.io.IOException;
import java.io.InputStream;

import nl.hro.mgdd.team4.raidersofhexagoniland.GameActivity;

import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.ITexture;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.texture.region.TextureRegionFactory;
import org.andengine.opengl.texture.bitmap.BitmapTexture;
import org.andengine.util.adt.io.in.IInputStreamOpener;
import org.andengine.util.debug.Debug;

public class SplashScene extends Scene {

	private ITexture _splashTexture;
    private ITextureRegion _splashTextureRegion;

    private Sprite _splash;
    
    public SplashScene() {

            try {
                    SceneManager.getManager();
					this._splashTexture = new BitmapTexture(
                                    SceneManager._game.getTextureManager(),
                                    new IInputStreamOpener() {
                                            @Override
                                            public InputStream open() throws IOException {
                                                    SceneManager.getManager();
													return SceneManager._game.getAssets()
                                                                    .open("gfx/splash.png");
                                            }
                                    });

                    this._splashTexture.load();
                    this._splashTextureRegion = TextureRegionFactory
                                    .extractFromTexture(this._splashTexture);

                    _splash = new Sprite(0, 0, this._splashTextureRegion,
                                    SceneManager._game.getVertexBufferObjectManager());
                    attachChild(_splash);
            } catch (IOException e) {
                    Debug.e(e);
            }
            
            final TimerHandler t = new TimerHandler(1.6f, new ITimerCallback(){
            	public void onTimePassed(final TimerHandler pTimerHandler){
            		SceneManager._game.getEngine().unregisterUpdateHandler(pTimerHandler);
            		GameActivity._manager.setMainMenuScene();
            	}
            });
            this.registerUpdateHandler(t);
            
    }
}